<template>
<Layout :showHome="false" :showH="false">
    <div class="container">
      <div class="header">
        <van-icon name="arrow-left" @click="$router.go(-1)"/>
          <h2>签约合同</h2>
          <van-icon name="" />
      </div>
      <div class="list" v-for="item in list" :key="item.id">
        <div class="item">
          <div class="text">
            <span>{{item.name}}</span>
            <i>{{item.time}}</i>
          </div>
            <van-button v-if="item.status === 0" color="#f56e00" plain round size="small" @click="$router.push('/sign/cont')">请签约</van-button>
            <van-button v-else color="#f56e00" plain round size="small" @click="$router.push('/sign/cont')">查看</van-button>
        </div>
      </div>
    </div>
  </Layout>
</template>

<script>
import { contractListApi, UserApi } from '../../apis/signApi'

export default {
  data () {
    return {
      // 合同列表
      list: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    // 获取列表
    async getList () {
      const userId = this.$store.getters['common/userId']
      const res = await UserApi(userId)
      const result = await contractListApi()
      if (res.active !== 2 || result.length === 0) {
        this.list = []
        this.$toast.fail('没有签约信息')
      } else {
        this.list = result
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import "../../style/common.less";

.container{
    padding: 0 20px;
    .header{
        padding-top: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        h2{
        font-size: 1rem;
        font-weight: normal;
        margin: 0;
        }
    }
    .list{
      margin-top: 20px;
      .item{
        padding: 20px;
        width: 90vw;
        height: 5rem;
        box-shadow: 0 0 5px rgb(218, 218, 218);
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-sizing: border-box;
        .text{
          display: flex;
          flex-direction: column;
          span{
            margin-bottom: 10px;
            color: @c1;
          }
          i{
            font-size: 0.7rem;
            color: @c3;
            font-style: normal;
          }
        }
        .van-button {
          width: 5rem;
        }
      }
    }
}
</style>